package com.carrot.uaa.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * 授权用户
 */
@Data
@JsonSerialize
@JsonIgnoreProperties(ignoreUnknown = true)
public class OAuth2User implements UserDetails, Serializable {

    /**
     * 用户主键
     */
    private String uid;

    /**
     * 租户ID
     */
    private String tenantId;

    /**
     * 用户名、昵称
     */
    private String nickname;

    /**
     * 账号
     */
    private String account;

    /**
     * 用户账号
     */
    private String sub;

    /**
     * 密码
     */
    private String password;

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 头像地址
     */
    private String avatar;


    /**
     * 用户类型
     */
    private String userType;

    /**
     * 身份类型
     */
    private String identityType;

    /**
     * 删除标志
     */
    private Integer deleted;

    /**
     * 状态
     */
    private String status;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.account;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return !(this.deleted != 0);
    }

    public static void main(String[] args) {
        OAuth2User auth2User = new OAuth2User();
        System.out.println(auth2User);
    }
}
